/*
 * Logging tool using Simple Log.
 */
package org.dbdir.core;

import org.grlea.log.SimpleLog;
import org.grlea.log.SimpleLogger;
import org.grlea.log.rollover.RolloverManager;

/**
 *
 * @author thotheolh
 */
public class Logger {

    private SimpleLog simplelog;
    private RolloverManager roller;
    private SimpleLogger syslogger = new SimpleLogger(this.getClass());
    private int globalMsgType = 0;//typeMsg: 0-info, 1-warning, 2-error, 3-fatal

    public Logger() {
//        try {
//            simplelog = new SimpleLog(new ConfigParser().getConfig("simplelog-config.properties"));
//            roller = new RolloverManager(new ConfigParser().getConfig("simplelog-rollover.properties"), null);
//        } catch (IOException ex) {
//            java.util.logging.Logger.getLogger(Logger.class.getName()).log(Level.SEVERE, null, ex);
//        }
    }

    public void log(int typeMsg, String message) {//typeMsg: 0-info, 1-warning, 2-error, 3-fatal
        if (typeMsg == 0) {
            syslogger.info("INFO|"+message);
        } else if (typeMsg == 1) {
            syslogger.warn("WARN|"+message);
        } else if (typeMsg == 2) {
            syslogger.error("ERR|"+message);
        } else if (typeMsg == 3) {
            syslogger.fatal("FATAL|"+message);
        } else {
            return;
        }
    }

    public void log(String message) {
        if (globalMsgType == 0) {
            syslogger.info("INFO|"+message);
        } else if (globalMsgType == 1) {
            syslogger.warn("WARN|"+message);
        } else if (globalMsgType == 2) {
            syslogger.error("ERR|"+message);
        } else if (globalMsgType == 3) {
            syslogger.fatal("FATAL|"+message);
        } else {
            return;
        }
    }

    /**
     * @return the globalMsgType
     */
    public int getGlobalMsgType() {
        return globalMsgType;
    }

    /**
     * @param globalMsgType the globalMsgType to set
     */
    public void setGlobalMsgType(int globalMsgType) {
        this.globalMsgType = globalMsgType;
    }
}
